
/*
 * @Description: 文件描述
 * @Version: 1.0
 * @Author: YueXuanzi
 * @Date: 2024-09-09 14:41:27
 * @LastEditors: YueXuanzi
 * @LastEditTime: 2024-09-29 11:09:02
 * @心得体会: 无
 */
import { createRouter, createWebHashHistory } from 'vue-router'
import Main from '@/views/Main.vue'
import NotFound from '@/pages/404.vue'
import { getToken } from '@/utils/auth'

const routes = [{
    // 登录
    path: '/login',
    name: "login",
    component: () => import('@/views/Login.vue')
  },
  {
    // 注册
    path: '/registerX',
    name: "registerx",
    component: () => import('@/views/Register.vue')
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component : NotFound
  },
  {
    path: '/',
    name: "main",
    component: Main,
    children: [{
      path: '/doctor',
      name: "doctor",
      component: ()=>import('@/views/doctor/Doctor.vue'),
    },{
      path: '/leave',
      name: 'leave',
      component: ()=>import('@/views/doctor/Leave.vue')
    },{
      path: '/record',
      name: 'record',
      component: ()=>import('@/views/doctor/Record.vue')
    },{
      path: '/register',
      name: 'register',
      component: ()=>import('@/views/doctor/Register.vue')
    },{
      path: '/visit',
      name: 'visit',
      component: ()=>import('@/views/doctor/Visit.vue')
    },
    { // 管理员模块
      path: '/user',
      name: 'user',
      component: ()=>import('@/views/user/User.vue')
    },
    {
      // 仓库
      path: '/bound',
      name: 'bound',
      component: ()=>import('@/views/user/bound/Bound.vue'),
      children: [{
        path: '/drug',
        name: 'drug',
        component: ()=>import('@/views/user/bound/Drug.vue')
      },{
        path: '/expire',
        name: 'expire',
        component: ()=>import('@/views/user/bound/Expire.vue')
      },{
        path: '/inout',
        name: 'inout',
        component: ()=>import('@/views/user/bound/Inout.vue')
      },{
        path: '/log',
        name: 'log',
        component: ()=>import('@/views/user/bound/Log.vue')
      }]
    },
    { // 基础信息
      path: '/information',
      name: 'information',
      component: ()=>import('@/views/user/information/Information.vue'),
      children: [{
        path: '/departmentinfo',
        name: 'departmentinfo',
        component: ()=>import('@/views/user/information/DepartmentInfo.vue')
      },{
        path: '/dept',
        name: 'dept',
        component: ()=>import('@/views/user/information/Dept.vue')
      },{
        path: '/doctorinfo',
        name: 'doctor2',
        component: ()=>import('@/views/user/information/DoctorInfo.vue')
      },{
        path: '/projectinfo',
        name: 'projectinfo',
        component: ()=>import('@/views/user/information/Project.vue')
      },{
        path: '/patientinfo',
        name: 'patientinfo',
        component: ()=>import('@/views/user/information/Patient.vue')
      },{
        path: '/supplier',
        name: 'supplier',
        component: ()=>import('@/views/user/information/Supplier.vue')
      }]
    },
    {// 房间管理
      path: '/room',
      name: 'room',
      component: ()=>import('@/views/user/room/Room.vue'),
      children: [
        {
          path: '/hospitalinfo',
          name: 'hospitalinfo',
          component: ()=>import('@/views/user/room/Hospitalinfo.vue')
        },
        {
          path: '/roominfo',
          name: 'roomInfo',
          component: ()=>import('@/views/user/room/RoomInfo.vue')
        },
      ]
    },{// 排班管理
      path: '/scheduling',
      name: 'scheduling',
      component: ()=>import('@/views/user/scheduling/Scheduling.vue'),
      children: [{
        path: '/doctortime',
        name: 'doctortime',
        component: ()=>import('@/views/user/scheduling/DoctorTime.vue')
      },{
        path: '/leave',
        name: 'leave',
        component: ()=>import("@/views/user/scheduling/Leave.vue")
      }
      ]
    },
    { // 系统管理
      path: "/setting",
      name: 'setting',
      component: ()=>import('@/views/user/usersetting/Setting.vue'),
      children: [{
        path: '/userinfo',
        name: 'userinfo',
        component: ()=>import('@/views/user/usersetting/UserInfo.vue')
      },{
        path: '/role',
        name: 'role',
        component: ()=>import('@/views/user/usersetting/Role.vue')
      },
      {
        path: '/menu',
        name: 'menu',
        component: ()=>import('@/views/user/usersetting/Menu.vue')
      }]
    },{
      path: "/complaint",
      name: 'complaint',
      component: ()=>import('@/views/user/Complaint.vue')
    } , // 其他
    {
      path: '/registerhospital',
      name: 'registerhospital',
      component: ()=>import('@/views/other/Registerhospital.vue')
    },{
      path: '/projectCheck',
      name: 'projectCheck',
      component: ()=>import('@/views/other/ProjectCheck.vue')
    },{
      path: '/registerOne',
      name: 'registerone',
      component: ()=>import('@/views/other/RegisterOne.vue')
    },{
      path: '/payregister',
      name: 'payregister',
      component: ()=>import('@/views/other/Payregister.vue')
    },
    {// 设置患者的
      path: '/patient',
      name: 'patient',
      component: ()=>import('@/views/patient/Patient.vue')
    },{
      path: '/appointment',
      name: 'appointment',
      component: ()=>import('@/views/patient/Appointment.vue')
    },{
      path: '/department',
      name: 'department',
      component: ()=>import('@/views/patient/Department.vue')
    },{
      path: '/reservation',
      name: 'reservation',
      component: ()=>import('@/views/patient/Reservation.vue')
    },{
      path: '/visitrecord',
      name: 'visitrecord',
      component: ()=>import('@/views/patient/Visitrecord.vue')
    },{
      path: '/pay',
      name: 'pay',
      component: ()=>import('@/views/patient/pay/Pay.vue'),
      children: [{
        path: '/discharge',
        name: 'discharge',
        component: ()=>import('@/views/patient/pay/Discharge.vue')
      },{
        path: '/project',
        name: 'project',
        component: ()=>import('@/views/patient/pay/Project.vue')
      },{
        path: '/prescription',
        name: 'prescription',
        component: ()=>import('@/views/patient/pay/Prescription.vue')
      }]

    }]
  }

]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  // to 将要访问的路径
  // from 代表从哪个路径跳转而来
  // next 是一个函数，表示放行
  //     next()  放行    next('/login')  强制跳转
  if (to.path == '/login'|| to.path == '/registerX') return next();
  // 获取token
  const token = getToken();
  // 没有token强制跳转登录页面
  if (!token) return next('/login');
  // 这里进行动态路由添加
  // if(storeUser.getters.getRouter.length != 0){
  //   const routerData = changeRouterData(storeUser.getters.getRouter)
  //   // router.addRoute(routerData)
  //   console.log(router)
  // }
  next();
})

// function changeRouterData(data){
//   let homeRouters = routes.filter(v=>v.path == '/')[0]
//   homeRouters.children = []
//   for(var i = 0; i < data.length; i++){
//     if(config[data[i].component] != undefined){
//       homeRouters.children.push({
//         path: data[i].path,
//         name: data[i].name,
//         component: ()=>import(config[data[i].component])
//       })
//     }
    
//   }
//   routes[2] = homeRouters
//   return homeRouters;
// }


export default router;











